package com.cloud.pole.common.util;

import org.joda.time.DateTimeUtils;

import javax.xml.crypto.Data;
import java.util.Date;

public class OrderNoUtils {

    private static final int SEQ_MAX_VALUE   = 9999;     //序列的最大值
    private static final int SEQ_MIN_VALUE   = 1000;     //序列的最小值
    private static Integer msgSEQ;  //消息的报文体序列号

    /**
     * 获取序列
     * @return
     */
    public static String getMsgSeq() {
        int nMsgSeq = 0;
        String msg = "";
        if (msgSEQ == null) {
            msgSEQ = new Integer(SEQ_MIN_VALUE);
        }
        synchronized (msgSEQ) {
            nMsgSeq = msgSEQ.intValue();
            if (nMsgSeq > SEQ_MAX_VALUE)
                nMsgSeq = SEQ_MIN_VALUE;
            msgSEQ = new Integer(nMsgSeq + 1);
            nMsgSeq = msgSEQ.intValue();
        }
        msg = Integer.toString(nMsgSeq);
        return msg;
    }

    /**
     * 获取订单号
     * @return
     */
    public  static String getOrderNo(){
        String strSeq = getMsgSeq();
        String strTime = DateUtils.formatDate(new Date(), DateUtils.DEFAULT_PATTERN);
        return  strTime  + strSeq;
    }
}
